package com.ask.controller;

import com.ask.dto.Result;
import com.ask.entity.Voucher;
import com.ask.service.businessService.IVoucherService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/voucher")
//@Tag(name = "优惠卷接口")
public class VoucherController {
    @Autowired
    private IVoucherService voucherService;

    /*------------------------管理端接口------------------------*/

    /**
     * 新增普通优惠卷
     * @param voucher
     * @return
     */
    @PostMapping
    public Result addVoucher(@RequestBody Voucher voucher) {
        Voucher vo = voucherService.addVoucher(voucher);
        return Result.success(voucher);
    }

    /**
     * 新增秒杀优惠卷
     * @param voucher
     * @return
     */
   // @Operation(summary = "新增秒杀卷")
    @PostMapping("/secKill")
    public Result addSecKillVoucher(@RequestBody Voucher voucher) {
        voucherService.addSecKillVoucher(voucher);
        return Result.success();
    }

    /*------------------------用户端接口------------------------*/

    /**
     * 获取店铺的优惠卷信息
     * @param shopId
     * @return
     */
    @GetMapping("/list/{id}")
    public Result listByShopId(@PathVariable("id") Long shopId) {
        List<Voucher> voucherList = voucherService.queryVoucherOfShop(shopId);
        return Result.success(voucherList);
    }
}
